home *** CD-ROM | disk | FTP | other *** search
- { Turbo Pascal routines to read the date and time
- Copywrite 1984 Michael A. Covington }
-
- { Each routine requires the following type definitions
- but does not require the other routines }
-
- type DateTimeType = string[8];
- regtype = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags: integer
- end;
-
- {==========================}
- function date: DateTimeType;
- {==========================}
-
- { return current date in form MM/DD/YY }
-
- var reg : regtype;
- y,m,d,w : DateTimeType;
- i : integer;
-
- begin
- reg.ax := $2A00;
- intr($21,reg);
- str(reg.cx:4,y);
- delete(y,1,2);
- str(hi(reg.dx):2,m);
- str(lo(reg.dx):2,d);
- w := m + '/' + d +'/' + y;
- for i := 1 to length(w) do if w[i] = ' ' then w[i] := '0';
- date := w
- end;
-
- {==========================}
- function time: DateTimeType;
- {==========================}
-
- { return current date in form HH:MM:SS }
-
- var reg : regtype;
- h,m,s,w : DateTimeType;
- i : integer;
-
- begin
- reg.ax := $2C00;
- intr($21,reg);
- str(hi(reg.cx):2,h);
- str(lo(reg.cx):2,m);
- str(hi(reg.dx):2,s);
- w := h + ':' + m +':' + s;
- for i := 1 to length(w) do if w[i] = ' ' then w[i] := '0';
- time := w
- end;
-
- {================================}
- procedure setdate(x:DateTimeType);
- {================================}
-
- { Sets date: Accepts string in format: MM/DD/YY }
-
- var reg : regtype;
- rh, rl, c1, c2, c3 : integer;
-
- begin
- reg.ax := $2B00;
- val(x[1]+x[2],rh,c1); { Month goes in DH }
- val(x[4]+x[5],rl,c2); { Day goes in DL }
- reg.dx := rh*256 + rl;
- val(x[7]+x[8],rl,c3); { Year goes in CX }
- reg.cx := rl + 1900;
- if rl<80 then reg.cx := reg.cx + 100; {21st century }
- c1 := c1+c2+c3; { return codes from Val }
- if c1 = 0 then intr($21,reg);
- if c1 + lo(reg.ax) <> 0 then begin
- writeln;
- writeln('Error -- invalid date: ''',x,'''');
- halt
- end
- end;
-
- {================================}
- procedure settime(x:DateTimeType);
- {================================}
-
- { Sets time: Accepts string in format: HH:MM:SS }
-
- var reg : regtype;
- rh, rl, c1, c2, c3 : integer;
-
- begin
- reg.ax := $2D00;
- val(x[1]+x[2],rh,c1); { Hours go in CH }
- val(x[4]+x[5],rl,c2); { Minutes go in CL }
- reg.cx := rh*256 + rl;
- val(x[7]+x[8],rl,c3); { Seconds go in DH }
- reg.dx := rh*256;
- c1 := c1+c2+c3; { return codes from Val }
- if c1 = 0 then intr($21,reg);
- if c1 + lo(reg.ax) <> 0 then begin
- writeln;
- writeln('Error -- invalid time: ''',x,'''');
- halt
- end
- end;